<%@page import="java.util.ArrayList"%>
<%@page import="edu.gatech.team404.Course"%>
<%@page import="edu.gatech.team404.Account"%>
<%@page import="edu.gatech.team404.AccountType"%>
<%@page import="edu.gatech.team404.dal.CourseDAL"%>
<%@page import="edu.gatech.team404.dal.AccountDAL"%>
<%@ page import="java.net.URLEncoder" %>

<div id="sidebar">
     	<div id="menu">
            <p style="text-align:center; padding:10px 0px 0px; margin:0px;"> Menu </p>
            <hr />
            
            <ul>
                <% 
	                String course = request.getParameter("course");
	                AccountDAL acctDal = new AccountDAL();
	           		Cookie username = getCookieByName(request.getCookies(), "username");	//ignore any error
	           		Account userAccount = acctDal.getAccount(username.getValue());
	           		
	               	if (course != null)
	               	{
	               		course = URLEncoder.encode(course,"UTF-8");
	               		out.println("<li><a href=\"default.jsp?course=" + course + "\">Home</a></li>");
	               		
	               		if (userAccount.getType() != AccountType.INSTRUCTOR) {
	               		out.println("<li><a href=\"courseRegister.jsp?course=" + course + "\">Register for Class</a></li>");
	               		}
	               		
		                out.println("<li><a href=\"lab.jsp?course=" + course + "\">Labs</a></li>");
		                out.println("<li><a href=\"team.jsp?course=" + course + "\">Teams</a></li>");
		                out.println("<li><a href=\"gradebook.jsp?course=" + course + "\">Gradebook</a></li>");
		                out.println("<li><a href=\"info.jsp?course=" + course + "\">Section Info</a></li>");
		                
		               	if (userAccount.getType() == AccountType.INSTRUCTOR) {
		               		out.println("<li><a href=\"report.jsp?course=" + course + "\">Report</a></li>");
		               	}
		               	else if (userAccount.getType() == AccountType.ADMIN) {
		               		out.println("<li><a href=\"report.jsp?course=" + course + "\">Report</a></li>");
		               		out.println("<li><a href=\"account.jsp?course=" + course + "\">Account</a></li>");
				            out.println("<li><a href=\"course.jsp?course=" + course + "\">Courses</a></li>");
		               	}
	               	}
	               	else {
	               		out.println("<li><a href=\"default.jsp\">Home</a></li>");
	               		
		               	if (userAccount.getType() == AccountType.INSTRUCTOR) {
		               		out.println("<li><a href=\"report.jsp\">Report</a></li>");
		               	}
		               	else if (userAccount.getType() == AccountType.ADMIN) {
		               		out.println("<li><a href=\"report.jsp\">Report</a></li>");
		               		out.println("<li><a href=\"account.jsp\">Account</a></li>");
				            out.println("<li><a href=\"course.jsp\">Courses</a></li>");
		               	}
	               	}
	               	acctDal.close();
                %>
            </ul>
    	</div>

       	<div id="course">
	    	<p style="text-align:center; padding:10px 0px 0px; margin:0px;"> Course </p>
	    	<hr />
	    	<ul>
	    		
	    		
		    	<% 	
		    		CourseDAL courseDal = new CourseDAL();
					ArrayList<Course> courses = (ArrayList<Course>) courseDal.getCoursesByStudent(username.getValue());
					for (Course crs : courses) {
						if (crs != null) {
							final String name = URLEncoder.encode(crs.getName(),"UTF-8");
							out.println("<li><a href=\"default.jsp?course=" + name + "\">" + crs.getName() + "</a></li>");
						}
					}
					courseDal.close();
				%>
	    	</ul>
    	</div>
       
    </div>